package com.wac.data.mapper;

import com.wac.data.entity.Friend;
import com.wac.data.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author beta
 * @since 2023-03-16
 */
public interface UserMapper extends BaseMapper<User> {

	// id查用户
	// @Select("select id,email,name,head_url,text,time from user where id = #{id}")
	// User selectById(String id);

	// 登录用&邮箱查用户
	@Select("select * from user where email = #{email}")
	User selectByEmail(String email);

	// 昵称查用户
	@Select("select * from user where name = #{name}")
	User selectByName(String name);

	// 注册用户
	@Insert("insert into user (email,name,password) values(#{email},#{name},#{password})")
	int addUser(String email, String name, String password);

	//获取用户的动态数量
	@Select("select count(*) from dynamic where user_id = #{userId}")
	int getdynamicNum(String userId);

	//获取用户的点赞数量
	@Select("select count(*) from `like` where belong_id = #{userId}")
	int getlikeNum(String userId);

	//获取用户的互相关注
	@Select("select friend2 as friend,`time` from is_friend where friend1=#{id}")
	List<Friend> getFriend(String id);

	//用户取消关注朋友破裂
	@Delete("delete from is_friend where friend1 = #{id} and friend2 = #{userId}")
	int deleteFriend(String id, String userId);

	// 签到天数+1
	@Update("update `user` set days = days + 1 where id = #{id}")
	int addDay(String id);

	// 增加经验值
	@Update("update `user` set exp = exp + #{exp} where id = #{id}")
	int addExp(int exp, String id);

	// 增加等级
	@Update("update `user` set level = level + 1 where id = #{id}")
	int addLevel(String id);
}
